package com.haiheng.module_main.dialog

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.haiheng.common.utils.BookUtil
import com.haiheng.library_base.dialog.BaseDialog
import com.haiheng.library_base.db.BookInfoBean
import com.haiheng.module_main.databinding.BookDetailDialogBinding

/**
 *
 * @Des:显示书籍详情弹框
 * @Author: hwz
 * @Date:2022/5/19 0019
 * @Version: 1.0
 */
class BookDetailDialog : BaseDialog() {

    companion object{
        @JvmStatic
        fun newInstance(): BookDetailDialog{
            return BookDetailDialog()
        }
    }

    private lateinit var binding: BookDetailDialogBinding
    private var bookInfo : BookInfoBean? = null


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        //设置背景透明，才能显示出layout中诸如圆角的布局，否则会有白色底（框）
        dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        binding = BookDetailDialogBinding.inflate(inflater,container,false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        dialog?.window?.apply { setDimAmount(0.5f) }
        binding?.slClose.setOnClickListener {
            dismiss()
        }
        iniDate()
    }

    fun iniDate(){
        binding?.tvBookName?.setText("${bookInfo?.bookTitle}")
        binding?.tvAuthor?.setText(bookInfo?.author)
        binding?.tvPublisher?.setText("${bookInfo?.publisher}")
        binding?.tvBarCode?.setText("${bookInfo?.barCode}")
        binding?.tvCallNumber?.setText("${bookInfo?.callNumber}")
        binding?.tvStatus?.setText("${BookUtil.getBookShelfStatus(bookInfo?.bookOnShelfStatus)}")
        binding?.tvFixLocation?.setText("${bookInfo?.fixedContainerSub?.name}")
        binding?.tvCurrentLocation?.setText("${bookInfo?.fixedContainerSub?.name}")

    }

    fun setBookDetail(bookInfo: BookInfoBean):BookDetailDialog{
        this.bookInfo= bookInfo
        return this
    }
}